home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / lang / sofa.lha / sofa / smalleiffel / lib_show / basic_time / example2.e < prev    next >
Text File  |  2000-03-25  |  1KB  |  63 lines

  1. class EXAMPLE2
  2. --
  3. -- This example shows how to know about time variation using
  4. -- class BASIC_TIME.
  5. --
  6.  
  7. creation make
  8.  
  9. feature {NONE}
  10.  
  11.    make is
  12.       local
  13.          time1, time2: BASIC_TIME;
  14.          sec, wait: INTEGER;
  15.       do
  16.          time1.update;
  17.          show_basic_time(time1);
  18.          from
  19.             sec := time1.second;
  20.             wait := 2;
  21.          until
  22.             wait = 0
  23.          loop
  24.             time2.update;
  25.             if time2.second /= sec then
  26.                sec := time2.second;
  27.                wait := wait - 1;
  28.             end;
  29.          end;
  30.          io.put_string("Elapsed time: ");
  31.          io.put_integer(time1.elapsed_seconds(time2));
  32.          io.put_string(" seconds%N");
  33.          show_basic_time(time2);
  34.          show_cpu_usage;
  35.       end;
  36.    
  37.    show_basic_time(basic_time: BASIC_TIME) is
  38.       do
  39.          io.put_string("hour: ");
  40.          io.put_integer(basic_time.hour);
  41.          io.put_string(" minute: ");
  42.          io.put_integer(basic_time.minute);
  43.          io.put_string(" second: ");
  44.          io.put_integer(basic_time.second);
  45.          io.put_string("%N");
  46.  
  47.       end;
  48.  
  49.    show_cpu_usage is
  50.       local
  51.          used_cpu: INTEGER;
  52.          basic_time: BASIC_TIME;
  53.       do
  54.          used_cpu := basic_time.clock_periods;
  55.          if used_cpu /= -1 then
  56.             io.put_string("CPU clock used: ");
  57.             io.put_integer(used_cpu);
  58.             io.put_string("%N");
  59.          end;
  60.       end;
  61.  
  62. end
  63.